package educar.cargo;



import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import educar.login.Session;
import educar.cargo.CargoController;

public class ModifCargoMediador implements ActionListener {
		
	private ModifCargoVentana view = new ModifCargoVentana();
		
	public ModifCargoMediador(){
		view.setVisible(true);
		view.addActionListener(this);
	}
	
	@SuppressWarnings("deprecation")
	public void actionPerformed(ActionEvent e) {
		Object obj = e.getSource();
		if(obj instanceof JButton){
			try {
				ListenerEvent(((JButton) obj).getLabel());
			} catch (CargoNoEncontrado e1) {
				e1.printStackTrace();
			}
		}
	}
	
	
	private void ListenerEvent(String event) throws CargoNoEncontrado{
		if(event.compareTo("Aceptar")==0){
			String codCargo = view.getCodCar();
			if (!CargoController.existe(codCargo))
				JOptionPane.showMessageDialog(null, "El docente no existe!");
			else {
				Cargo doc = CargoController.getCargo(codCargo);
				ModificarCargoMediador modif = new ModificarCargoMediador(doc);
				view.limpiar();
			}
			
		}
		if (event.compareTo("Cancelar")==0)
			view.dispose();
	}
}
